﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GrayParrot.ServiceBroker.Configuration
{
    /// <summary>
    /// Subscription setting class...
    /// </summary>
    /// <seealso cref="System.Configuration.ConfigurationElement" />
    public class Subscription : ConfigurationElement
    {
        /// <summary>
        /// Gets or sets the connection string.
        /// </summary>
        /// <value>
        /// The connection string for connects to the service bus endpoint...
        /// </value>
        public string ConnectionString { get; set; }

        /// <summary>
        /// Gets or sets the subscription.
        /// </summary>
        /// <value>
        /// The service bus subscription...
        /// </value>
        [ConfigurationProperty("name", IsRequired = true, IsKey = true)]
        public string Name
        {
            get { return (string)base["name"]; }
            set { base["name"] = value; }
        }

        /// <summary>
        /// Gets or sets the topic.
        /// </summary>
        /// <value>
        /// The service bus topic.
        /// </value>
        [ConfigurationProperty("topicSend", IsRequired = true, IsKey = false)]
        public string TopicSend
        {
            get { return (string)base["topicSend"]; }
            set { base["topicSend"] = value; }
        }

        /// <summary>
        /// Gets or sets the name of the message.
        /// </summary>
        /// <value>
        /// The message name defined in the default rule for the subscription...
        /// </value>
        [ConfigurationProperty("topicReceive", IsRequired = true, IsKey = false)]
        public string TopicReceive
        {
            get { return (string)base["topicReceive"]; }
            set { base["topicReceive"] = value; }
        }

        /// <summary>
        /// Gets or sets the topic dead letter.
        /// </summary>
        /// <value>
        /// The topic dead letter.
        /// </value>
        [ConfigurationProperty("topicSendDeadLetter", IsRequired = true, IsKey = false)]
        public string TopicSendDeadLetter
        {
            get { return (string)base["topicSendDeadLetter"]; }
            set { base["topicSendDeadLetter"] = value; }
        }

        /// <summary>
        /// Gets or sets the topic receive dead letter.
        /// </summary>
        /// <value>
        /// The topic receive dead letter.
        /// </value>
        [ConfigurationProperty("topicReceiveDeadLetter", IsRequired = true, IsKey = false)]
        public string TopicReceiveDeadLetter
        {
            get { return (string)base["topicReceiveDeadLetter"]; }
            set { base["topicReceiveDeadLetter"] = value; }
        }

        /// <summary>
        /// Gets or sets a value indicating whether [read from dead letter].
        /// </summary>
        /// <value>
        ///   <c>true</c> if [can read from dead letter]; otherwise, <c>false</c>.
        /// </value>
        [ConfigurationProperty("readDL", IsRequired = false, IsKey = false)]
        public bool ReadDL
        {
            get { return (bool)base["readDL"]; }
            set { base["readDL"] = value; }
        }

        /// <summary>
        /// Gets or sets the type of the format.
        /// </summary>
        /// <value>
        /// The type of the format used to serialize the service bus message body...
        /// </value>
        [ConfigurationProperty("formatType", IsRequired = false, IsKey = false)]
        public FormatTypes FormatType
        {
            get { return (FormatTypes)base["formatType"]; }
            set { base["formatType"] = value; }
        }

        /// <summary>
        /// Gets or sets the number of retries on failure...
        /// </summary>
        /// <value>
        /// The number of retries on failure...
        /// </value>
        /// <remarks>
        /// The number of retries on failure default value is 10...
        /// </remarks>
        [ConfigurationProperty("numberOfRetryonFailure", IsRequired = true, IsKey = false)]
        public UInt16 NumberOfRetriesOnFailure
        {
            get { return (UInt16)base["numberOfRetryonFailure"]; }
            set { base["numberOfRetryonFailure"] = value; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Endpoint"/> class.
        /// </summary>
        public Subscription()
        {
            this.FormatType = FormatTypes.Binary;
            this.NumberOfRetriesOnFailure = 10;
        }
    }
}
